#include "stdafx.h"
#include "CallBacks.h"
#include "Defines.h"
#include "Exceptions.h"
#include "Maze.h"

CMaze *g_theMaze = NULL;

void myInit(void)
{
	glClearColor(BACKGROUND_COLOR, 0.0);
	//glColor3f(1.0f, 1.0f, 1.0f);
	//glPointSize(1.0f);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, (float)X_RES, 0.0, (float)Y_RES);
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

	glutInitWindowSize(X_RES, Y_RES);

	glutInitWindowPosition(70, 30);

	glutCreateWindow("Maze : press 'c' to create maze, 'r' to find route");

	glutDisplayFunc (myDisplay);
	glutKeyboardFunc(myKeyboard);

	//glutFullScreen();

	myInit();

	//_crtBreakAlloc = 41;

	try
	{
		g_theMaze = new CMaze(MAZE_Y_SIZE, MAZE_X_SIZE);
	}
	catch(CMazeException err)
	{
		err.Message();

		if(g_theMaze)
		{
			delete g_theMaze;
			g_theMaze = NULL;
		}
	
		glutSetWindowTitle("Maze creation error");
	}

	/*if(g_theMaze)
	{
		delete g_theMaze;
		g_theMaze = NULL;
	}

	_CrtDumpMemoryLeaks();
	*/

	glutMainLoop();

	if(g_theMaze)
	{
		delete g_theMaze;
		g_theMaze = NULL;
	}

	return 0;
}



